<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改活动商品')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-product-edit" th:object="${activityProduct}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">商品id：</label>
                <div class="col-sm-8">
                    <input name="productId" th:field="*{productId}" class="form-control" style="width: 450px;" type="text">
                    <button type="button" class="btn btn-success btn-sm" onclick="addProduct()">添加</button>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">活动商品名称：</label>
                <div class="col-sm-8">
                    <input name="name" th:field="*{name}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">是否为满减商品：</label>
                <div class="col-sm-8">
                    <label class="radio-box"> <input type="radio" name="isRebate" value="1" th:checked="*{isRebate==1}"/> 是 </label>
                    <label class="radio-box"> <input type="radio" name="isRebate" value="0" th:checked="*{isRebate==0}"/> 否 </label>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">实收金额：</label>
                <div class="col-sm-8">
                    <input name="payment" th:field="*{payment}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">发放数量：</label>
                <div class="col-sm-8">
                    <label class="radio-box"> <input type="radio" name="isCount" value="0" th:checked="*{isCount==0}"/> 不限 </label>
                    <label class="radio-box"> <input type="radio" name="isCount" value="1" th:checked="*{isCount==1}"/> 含数量限制 </label>
                </div>
            </div>
            <div class="form-group count">
                <label class="col-sm-3 control-label">数量限制：</label>
                <div class="col-sm-8">
                    <input name="count" th:field="*{count}" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <script type="text/javascript">
        var isCount = [[${activityProduct.isCount}]];
        var prefix = ctx + "activity/product";
        $("#form-product-edit").validate({
            focusCleanup: true
        });
        $("input[name='isCount']").on('ifChecked', function(event){
            init(this.value)
        });

        function  init(val){
            if(val==0){
                $('.count').hide();

            }else if (val==1){
                $('.count').show();

            }else {
                $('.count').hide();

            }
        }
        init(isCount)


        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-product-edit').serialize());
            }
        }

        //选择商品
        function addProduct() {
            let addProductUrl = prefix + "/selectProduct";
            $.modal.open("选择商品", addProductUrl);
        }
    </script>
</body>
</html>